package com.cryptape.cita_wallet.constant;

import android.os.Environment;

import com.cryptape.cita_wallet.util.ether.EtherUtil;

import java.math.BigInteger;

/**
 * Created by duanyytop on 2018/11/12.
 */
public class ConstantUtil {

    public static final String DEFAULT_CURRENCY = "USD";

    public static final String RPC_RESULT_ZERO = "0x";

    // ERC20 method hashes
    public static final String ZERO_16 = "000000000000000000000000";
    public static final String NAME_HASH = "06fdde03";
    public static final String SYMBOL_HASH = "95d89b41";
    public static final String DECIMALS_HASH = "313ce567";
    public static final String BALANCE_OF_HASH = "70a08231";

    public static final String FINGERPRINT_TIP = "FINGERPRINT_TIP";
    public static final String FINGERPRINT = "Fingerprint";
    public static final String CURRENCY = "Currency";
    public static final String PROTOCOL = "Protocol";
    public static final String SENSOR_IP_ID = "SENSOR_IP_ID";

    public static final String IMG_SAVE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/";


    // CITA Constant
    public static final String QUOTA_PRICE_DEFAULT = "1";
    public static final BigInteger QUOTA_TOKEN = new BigInteger("21000");
    public static final BigInteger QUOTA_ERC20 = new BigInteger("250000");
    public static final BigInteger QUOTA_ERC20_BIG_1 = new BigInteger("1500000");
//    public static final BigInteger QUOTA_ERC20_BIG = new BigInteger("2000000");
//    public static final BigInteger QUOTA_ERC20_BIG = new BigInteger("2500000");
    public static final BigInteger QUOTA_ERC20_BIG = new BigInteger("2300000");

    public static final BigInteger QUOTA_ERC20_BIG_APPEND = new BigInteger("500000");

    public static final BigInteger GAS_PRICE_BIG = new BigInteger("2");

    public static final BigInteger GAS_PRICE_BIG_1 = new BigInteger("8000000000");

    public static final String MBA_CHAIN_ID = "2";
    public static final String MBA_CHAIN_NAME = "mba-testnet";
    public static final String MBA_TOKEN_NAME = "Merchant Base Assert";
    public static final String MBA_TOKEN_SYMBOL = "MBA";
    public static final String MBA_TOKEN_AVATAR = "https://download.mba.cmbchina.biz/images/MBA-logo.jpg";
    public static final String MBA_HTTP_PROVIDER = "http://testnet.mba.cmbchina.biz:1337";

    public static final String GLD_CHAIN_ID = "-100";
    public static final String GLD_CHAIN_NAME = "Ethereum Ropsten";
    public static final String GLD_TOKEN_NAME = "GLD";
    public static final String GLD_TOKEN_SYMBOL = "GLD";
    public static final String GLD_TOKEN_AVATAR = "https://download.mba.cmbchina.biz/images/MBA-logo.jpg";
    public static final String GLD_HTTP_PROVIDER = "http://testnet.mba.cmbchina.biz:1337";


    public static final String HCOIN_CHAIN_ID = "-106";
    public static final String HCOIN_CHAIN_NAME = "Ethereum Ropsten";
    public static final String HCOIN_TOKEN_NAME = "HCOIN";
    public static final String HCOIN_TOKEN_SYMBOL = "HCOIN";
    public static final String HCOIN_TOKEN_AVATAR = "https://download.mba.cmbchina.biz/images/MBA-logo.jpg";
    public static final String HCOIN_HTTP_PROVIDER = "http://testnet.mba.cmbchina.biz:1337";

    public static final String MGP_CHAIN_ID = "-101";
    public static final String MGP_CHAIN_NAME = "Ethereum Ropsten";
    public static final String MGP_TOKEN_NAME = "MGP";
    public static final String MGP_TOKEN_SYMBOL = "MGP";
    public static final String MGP_TOKEN_AVATAR = "https://download.mba.cmbchina.biz/images/MBA-logo.jpg";
    public static final String MGP_HTTP_PROVIDER = "http://testnet.mba.cmbchina.biz:1337";

    public static final String HMIO_CHAIN_ID = "-102";
    public static final String HMIO_CHAIN_NAME = "Ethereum Ropsten";
    public static final String HMIO_TOKEN_NAME = "HMIO";
    public static final String HMIO_TOKEN_SYMBOL = "HMIO";
    public static final String HMIO_TOKEN_AVATAR = "https://download.mba.cmbchina.biz/images/MBA-logo.jpg";
    public static final String HMIO_HTTP_PROVIDER = "http://testnet.mba.cmbchina.biz:1337";


    public static final String DEFAULT_CHAIN_ID = "1";
    public static final String DEFAULT_CHAIN_NAME = "test-chain";
    public static final String DEFAULT_TOKEN_NAME = "CITA Test Token";
    public static final String DEFAULT_TOKEN_SYMBOL = "CTT";
    public static final String DEFAULT_TOKEN_AVATAR = "https://cdn.cryptape.com/icon_appchain.png";
    public static final String DEFAULT_HTTP_PROVIDER = "https://node.cryptape.com";

    public static final long VALID_BLOCK_NUMBER_DIFF = 80L;


    public static final String TYPE_ETH = "ETH";
    public static final String TYPE_CITA = "CITA";

    // Ether Constant
    public static final String ETH = "ETH";
    private static final String DEFAYLT_COIN = "MGP";
    private static final String GLD = "GLD";
    public static final String ETHEREUM = "ethereum";
    public static final String ETH_MAINNET = "Ethereum Mainnet";
    public static final String GWEI = "GWei";
    public static final double MIN_GWEI = 1;

    public static final String ETH_NET = "ETH_NET";
    public static final String ETH_NET_MAIN = "Main Ethereum Network";
    public static final String ETH_NET_ROPSTEN_TEST = "Ropsten Test Network";
    public static final String ETH_NET_KOVAN_TEST = "Kovan Test Network";
    public static final String ETH_NET_RINKEBY_TEST = "Rinkeby Test Network";

    public static final String ETHEREUM_MAIN_ID = "-1";
    public static final String ETHEREUM_ROPSTEN_ID = "-3";
    public static final String ETHEREUM_KOVAN_ID = "-42";
    public static final String ETHEREUM_RINKEBY_ID = "-4";


    public static final String ETH_MAIN_NAME = "Ethereum Mainnet";
    public static final String ETH_RINKEBY_NAME = "Ethereum Rinkeby";
    public static final String ETH_KOVAN_NAME = "Ethereum Kovan";
    public static final String ETH_ROPSTEN_NAME = "Ethereum Ropsten";

    // gas constant data
    public static final BigInteger GAS_LIMIT = new BigInteger("21000");        // default eth gas limit is 21000
    public static final BigInteger GAS_ERC20_LIMIT = new BigInteger("100000");  // default eth gas limit is 100000
//    public static final BigInteger GAS_LIMIT_PARAMETER = BigInteger.valueOf(4);
    public static final BigInteger GAS_LIMIT_PARAMETER = BigInteger.valueOf(4);
    public static final BigInteger GAS_ERC20_LIMIT_DEFAULT = new BigInteger("400000");

//    MToken:0x8a845fc339ceb022a695281554890429a34df120
//    HToken:0x155697df0d39e18f719fa58e25a53a65ccb4864e
//    会员关系：0x5fcb9bd84773225311b6210b4e98d954f3e8ea3a
//    会员注册：0xfC0A35f6A6bC5531519f71CF70193C17B44508FB
//    兑换合约：0x4B66401080AF000962835b696fcE87BF2e94a653

    private static final String EXCHANGE_CONTRACT = "0x4B66401080AF000962835b696fcE87BF2e94a653";
    private static final String RELATION_CONTRACT = "0x02fd92D1bff7bb29d755EBCC16F34Ee986879ceD";// "0xCB00A25BDf7B58995554e852A9D820cE9C49C5B8";
    private static final String REGISTER_CONTRACT = "0x2b7f25011B852E8bD6E6c733f4D39345a75d2680";//"0x4BAfDD63F6B2BEcCF86D02981B84332A63562D08";
    private static final String MToken = "0x8a845fc339ceb022a695281554890429a34df120";
    private static final String HToken = "0x155697df0d39e18f719fa58e25a53a65ccb4864e";

//    M币:0xb2054aDd212F19581aEB195FDa7644471a996134
//    H币:0x35f80690aC86D21f180650B960Ca624F4980228E
//    会员关系:0x0E18b3C54518f811EEc271fd493A2116B6d31c95
//    会员注册:0x3302fCCd24f17cE64D8547A166704F5988b63169
//    众筹合约:0xd03674502386dca717690e321D0EdDbC4D06c9a8
//    下单合约:0xF2Ae6bfE3dFf364b2CEd917a7305788Be1Ad6570

    private static final String GLDToken = "0xb2054aDd212F19581aEB195FDa7644471a996134";
    private static final String HTokenTest = "0x35f80690aC86D21f180650B960Ca624F4980228E";
    private static final String EXCHANGE_CONTRACT_TEST = "0x5E737774e2E6b4fa371568b021cF4802d29c5604";
    private static final String RELATION_CONTRACT_TEST ="0x0E18b3C54518f811EEc271fd493A2116B6d31c95";// "0xCB00A25BDf7B58995554e852A9D820cE9C49C5B8";
    private static final String REGISTER_CONTRACT_TEST = "0x3302fCCd24f17cE64D8547A166704F5988b63169";//"0x4BAfDD63F6B2BEcCF86D02981B84332A63562D08";
//    public static final String DEPOSIT_CONTRACT = "0xF2Ae6bfE3dFf364b2CEd917a7305788Be1Ad6570";//"0x1dfDB31ed750e79CA1CA45a343C869D2AD19E4cC";

    public static final String DEPOSIT_CONTRACT = "0x7a814a19b20e89Ffdc5d8474102f7184F8d4C2E8";//"0x5871A0593bB5e3a9d8362Bf1863A119d42C0d23f";
    private static final String MINER_SELL_CONTRACT_TEST = "0x7CEEEd8a2BFb52283e7844B87992d0477910CBa7";//"0x5871A0593bB5e3a9d8362Bf1863A119d42C0d23f";
    private static final String MINER_SELL_CONTRACT = "0x651f2fb63a4C6F94a6E97BaccF934cc346d1b976";//"0x5871A0593bB5e3a9d8362Bf1863A119d42C0d23f";


    public static String getMinerSellContract(){
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return MINER_SELL_CONTRACT_TEST;
        } else {
            return MINER_SELL_CONTRACT;
        }
    }

//    public static final String DEPOSIT_CONTRACT = "0xdC6C0D2cB76B16b9FAFae7ee554f481e35d43c17";//"0x5871A0593bB5e3a9d8362Bf1863A119d42C0d23f";

//    public static final String DEPOSIT_CONTRACT = "0x99d68f81d2dF8a95816De92BC79864C8a0b5De42";//"0x5871A0593bB5e3a9d8362Bf1863A119d42C0d23f";
//    public static final String ERC777_CONTRACT = "0xb2054aDd212F19581aEB195FDa7644471a996134";
//

//    public static final String DEPOSIT_CONTRACT = "0xB34B5F9aC4FB6b2E30c157Ef53433e0B2aC267dd";
//    public static final String DEPOSIT_CONTRACT = "0x24fbD4E6786049fbbD18c02D5F52d08b4FD69B56";
//    public static final String DEPOSIT_CONTRACT = "0xd66E80960E80C39a5ff78160759CCFb2AF666E9B";
    public static String getRegisterContract(){
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return REGISTER_CONTRACT_TEST;
        } else {
            return REGISTER_CONTRACT;
        }
    }

    public static String getRELATIONContract(){
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return RELATION_CONTRACT_TEST;
        } else {
            return RELATION_CONTRACT;
        }
    }

    public static String getExchangeContract(){
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return EXCHANGE_CONTRACT_TEST;
        } else {
            return EXCHANGE_CONTRACT;
        }
    }

    public static String getHToken(){
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return HTokenTest;
        } else {
            return HToken;
        }
    }

    public static String getMGPToken(){
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return GLDToken;
        } else {
            return MToken;
        }
    }

    public static String getMGPName(){
//        return MGP_TOKEN_SYMBOL;
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return GLD;
        } else {
            return MGP_TOKEN_SYMBOL;
        }
    }

//pole hurt reason tray harsh opinion doctor student access achieve suit stomach
    public static String getDefaultCoin() {
        if (EtherUtil.getEthNodeName().equals(ConstantUtil.ETH_ROPSTEN_NAME)) {
            return GLD;
        } else {
            return DEFAYLT_COIN;
        }
    }

//
//    public RemoteFunctionCall<Tuple3<List<BigInteger>, List<BigInteger>, List<Boolean>>> minerDetail(BigInteger buyType) {
//        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_MINERDETAIL,
//                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(buyType)),
//                Arrays.<TypeReference<?>>asList(
//                        new TypeReference<DynamicArray<Uint256>>() {},
//                        new TypeReference<DynamicArray<Uint256>>() {},
//                        new TypeReference<DynamicArray<Bool>>() {}));
//        return new RemoteFunctionCall<Tuple3<List<BigInteger>, List<BigInteger>, List<Boolean>>>(function,
//                new Callable<Tuple3<List<BigInteger>, List<BigInteger>, List<Boolean>>>() {
//                    @Override
//                    public Tuple3<List<BigInteger>, List<BigInteger>, List<Boolean>> call() throws Exception {
//                        List<Type> results = executeCallMultipleValueReturn(function);
//                        return new Tuple3<List<BigInteger>, List<BigInteger>, List<Boolean>>(
//                                convertToNative((List<Uint256>) results.get(0).getValue()),
//                                convertToNative((List<Uint256>) results.get(1).getValue()),
//                                convertToNative((List<Bool>) results.get(2).getValue()));
//                    }
//                });
//    }

}
//nuclear trigger involve vibrant myself relief monkey top bulk hill trust resource
// success bargain patient habit rail home result note stadium fade danger cool
//water boost certain cheese oblige night chicken address venture basket garden rifle




//https://api-cn.etherscan.com/api?apikey=T9GV1IF4V7YDXQ8F53U1FK2KHCE2KUUD8Z&module=account&action=tokentx&sort=desc&contractaddress=0x8a845Fc339CeB022A695281554890429a34DF120&address=0xcEE5700b976ac40c536B43c2F4Fd39d9BaFADFC7&page=0&offset=20
//http://api-cn.etherscan.com/api?apikey=T9GV1IF4V7YDXQ8F53U1FK2KHCE2KUUD8Z&module=account&action=tokentx&sort=desc&contractaddress=0x8a845fc339ceb022a695281554890429a34df120&address=0xf4128a3E1da533C84A26a3Af5286c0ccF65EffD5&page=1&offset=10